<div class="row">
	<div class="col-md-12">
		<ol class="breadcrumb">
			<li>
				<a href="#" onclick="toHome()">
					主页
				</a>
			</li>
			<li class="active">
				积分账户调整
			</li>
		</ol>
	</div>
</div>
<form role="form" class="form-horizontal">
	<div class="row page-cont">
		<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 cont-top">
			<div class="panel panel-white">
				<div class="panel-heading">
					<h4 class="panel-title">
						<span class="title-text">积分账户</span>
					</h4>
					<div class="panel-tools">
						<div class="dropdown">
							<a data-toggle="dropdown" class="btn btn-xs dropdown-toggle btn-transparent-grey">
								<i class="fa fa-cog"></i>
							</a>
							<ul class="dropdown-menu dropdown-light pull-right" role="menu">
								<li>
									<a class="panel-collapse collapses" href="#"><i class="fa fa-angle-up"></i> <span>折叠</span> </a>
								</li>
								<li>
									<a class="panel-expand" href="#">
										<i class="fa fa-expand"></i> <span>全屏</span>
									</a>
								</li>
							</ul>
						</div>
						<a class="btn btn-xs btn-link panel-close" href="#">
							<i class="fa fa-times"></i>
						</a>
					</div>
				</div>
				<div class="panel-body">
					<div class="form-group panel-cont">
					    <label class="col-sm-2 control-label">参数类型</label>
					    <div class="col-sm-4">
					    	<select>
					    		<option value="">手机号</option>
					    		<option value="">昵称</option>
					    		<option value="">用户编号uid</option>
					    	</select>
					    </div>
				  	</div>
					<div class="form-group panel-cont">
					    <label class="col-sm-2 control-label">调账参数</label>
					    <div class="col-sm-4">
					      	<input type="text" class="form-control" />
					    </div>
				  	</div>	
					<div class="form-group panel-cont">
					    <label class="col-sm-2 control-label">调账积分</label>
					    <div class="col-sm-4">
					      	<input type="text" class="form-control" />
					    </div>
						<span class="col-sm-4 tips">
					    	<i class="fa fa-info-circle"></i>
					    	最多保留两位小数
					    </span>					    
				  	</div>					  	
					<div class="form-group panel-cont">
					    <label class="col-sm-2 control-label">调账原因</label>
					    <div class="col-sm-4">
					      	<input type="text" class="form-control" />
					    </div>
						<span class="col-sm-4 tips">
					    	<i class="fa fa-info-circle"></i>
					    	必填
					    </span>						    
				  	</div>					  	
					<div class="form-group panel-cont">
					    <label class="col-sm-2 control-label">操作类型</label>
					    <div class="col-sm-4">
					     	<select>
					    		<option value="">加</option>
					    		<option value="">减</option>
					    	</select>
					    </div>
						<span class="col-sm-4 tips">
					    	<i class="fa fa-info-circle"></i>
					    	请选择加钱还是减钱
					    </span>						    
				  	</div>					  				  	
				  	<div class="form-group">
				  		<div class="col-sm-5 col-sm-offset-2">
				  			<button type="button" class="btn btn-red" id="check-btn">调账<i class="fa fa-arrow-circle-right"></i></button>
				  		</div>
				  	</div>
				</div>
			</div>
		</div>
	</div>
</form>
<script>

	/**********************************************变量**********************************************/
	var pageNo = 1;    // 第几页
	var pageSize = 10;  // 每页几条
	var totalPage;     // 总页数
	var username = GetQueryString("username");      // 用户姓名
	var token = MXCookie.get("token",token);        // 登陆token   

	/**********************************************事件**********************************************/
	// 新增
   	toOperat($(".add-btn"),"view/funcManage/add-func.html");
	// 查看
   	toOperat($(".check-btn"),"view/funcManage/view-func.html");   
	// 编辑
   	toOperat($(".edit-btn"),"view/funcManage/edit-func.html");     	

	// 查询
	$("#check-btn").click(function(){
		name = $("#couponName").val();
		cardType = $("#card-type").find("option:selected").val();
		startTime = $("#startDate").val();
		endTime = $("#endDate").val();
		// getList(name,cardType,startTime,endTime,pageNo);
	});

	/**********************************************函数**********************************************/
	// 获取通兑卡列表
	function getList(name,cardType,startTime,endTime) {
		$("tbody").html("");
		$.ajax({
			url: localStorage.grobalUrl + "/discount/discountList",
			type: "post",
			async:false,
			data:{
				username: username,
				token: token,
				name: name,
				prefix: cardType,
				beginDate: startTime,  
				endDate: endTime,  
				pageNo: pageNo,   
				pageCount: pageSize
			},
			success: function(data){
				console.log(data);
				var str =  '<tr align="center">'+
								'<td class="card-id">2343</td>'+
								'<td class="card-name">3423</td>'+
								'<td class="card-intro"></td>'+
								'<td class="max-price"></td>'+
								'<td class="start-time"></td>'+
								'<td class="end-time"></td>'+
								'<td>'+
									'<button type="button" class="btn btn-dark-yellow check-btn">查看&nbsp;<i class="fa fa-eye"></i></button>'+
									'<button type="button" class="btn btn-red delete-btn">删除&nbsp;<i class="fa fa-trash-o"></i></button>'+
									'<button type="button" class="btn btn-dark-yellow coupon-btn">生成优惠券&nbsp;<i class="fa fa-caret-square-o-down"></i></button>'+
									'<button type="button" class="btn btn-dark-yellow export-btn">导出&nbsp;<i class="fa fa-arrow-circle-down"></i></button>'+
									'<button type="button" class="btn btn-dark-yellow bind-btn">批量绑定&nbsp;<i class="fa fa-arrow-circle-down"></i></button>'+
									'<button type="button" class="btn btn-dark-yellow bind-view">查看批量绑定&nbsp;<i class="fa fa-arrow-circle-down"></i></button>'+
								'</td>'+
							'</tr>';
				if(data.errCode == "00005"){
					tips("请重新登陆");
					setTimeout(function(){
						window.location.href = "login_login.html";
					},500);
				}
				if (data.couponPage){
				  	var dataVal = data.couponPage.list;
			        totalPage = data.couponPage.totalPage;
			        for(var i = 0; i < dataVal.length; i ++){
			            var cardVal = dataVal[i];
			            $("tbody").append(str);
			            $(".card-id").eq(i).text(cardVal.id);
			            $(".card-name").eq(i).text(cardVal.name);
			            $(".card-intro").eq(i).text(cardVal.introduction);
			            $(".max-price").eq(i).text(cardVal.maximum_price);
			            $(".start-time").eq(i).text(cardVal.begin_date);
			            $(".end-time").eq(i).text(cardVal.end_date);
			        }
			  
			        // 删除按钮
			        $(".delete-btn").click(function(){
			            var index = $(".delete-btn").index(this);
			            console.log(index);
			            var cardId = $(".card-id").eq(index).text();
			            deleteList(cardId,index);
			        });
			  
			        // 查看
			        jumpTo($(".check-btn"),"view/exchangeCard/card-view.html");
			  
			        // 生成优惠券
			        jumpTo($(".coupon-btn"),"view/exchangeCard/create-coupon.html");
			  
			        // 导出
			        $(".export-btn").click(function(){
			            var index = $(".export-btn").index(this);
			            cardId = $(".card-id").eq(index).text();            
			            exportFun(cardId);
			        }); 

			        // 批量绑定
			       jumpTo($(".bind-btn"),"view/exchangeCard/bind-card.html");
			       // 查看批量绑定
			       jumpTo($(".bind-view"),"view/exchangeCard/bind-view.html");
				}else{
				  $("tbody").append("<tr><td align='center' colspan='11'>暂无数据</td></tr>");
				}
					
			},
			error: function(error){
				console.log(error);
			}
		});	
	}
	// getList();

	// // 分页
	// pageSetGet();


	// 跳转（查看/生成优惠券）
	function jumpTo(tag,pageUrl){
		tag.click(function(){
	        var index = tag.index(this);
	        cardId = $(".card-id").eq(index).text();
	        $(".pageAdd").attr("data-id",cardId);
	        url = pageUrl;
	        getPage(url); 
	    });		
	}
			



	// 删除
	function deleteList(cardId,index){
		$.ajax({
			url: localStorage.grobalUrl + "/discount/deleteDiscount",
			type:"post",
			data: {
				username: username,
				token: token,				
				couponId: cardId
			},
			success: function(data){
				console.log(data);
				if(data.errCode == "00000"){
					$(".delete-btn").eq(index).parent().parent().remove();
				}else if(data.errCode == "00005"){
					tips("请重新登陆");
					setTimeout(function(){
						window.location.href = "login_login.html";
					},500);					
				}else{
					tips("删除失败");
				}
			},
			error: function(error){
				console.log(error);
			}
		});
	}
	
</script>
